package cn.lkk.samples.lang.interfaces.definition;

/**
 * 演示接口的基本使用。
 * Employee 类实现了 Comparable 接口，可以进行比较。
 */
public class Employee implements Comparable<Employee> {
    private String name;
    private double salary;

    public Employee(String name, double salary) {
        this.name = name;
        this.salary = salary;
    }

    public String getName() {
        return name;
    }

    public double getSalary() {
        return salary;
    }

    public void raiseSalary(double byPercent) {
        double raise = salary * byPercent / 100;
        salary += raise;
    }


    //需要显示声明为public，定义中不需要加public关键字，因为是默认的
    @Override
    public int compareTo(Employee o) {
        //内置类型的比较可以使用对应的包装类中提供的方法
        return Double.compare(this.salary, o.salary);
    }
}
